package com.example.module.iot.emq.callback;

import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallbackExtended;
import org.eclipse.paho.client.mqttv3.MqttMessage;

@Slf4j
public class EmqxCallback implements MqttCallbackExtended {

    @Override
    public void connectionLost(Throwable throwable) {
        log.error("MQTT连接断开，e: {}", throwable.getMessage());
    }

    @Override
    public void messageArrived(String topic, MqttMessage mqttMessage) {
        log.info("MQTT收到消息，topic: {}, content: {}", topic, new String(mqttMessage.getPayload()));
    }

    @Override
    public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
        log.debug("发布消息成功，iMqttDeliveryToken: {}", iMqttDeliveryToken);
    }

    @Override
    public void connectComplete(boolean reconnect, String serverURI) {
        log.info("MQTT 已连接到服务器: {}", serverURI);
    }
}
